const { Goods } = require('../../../model/goods')
const { News } = require('../../../model/news')
const { User } = require('../../../model/user')
const { goodsState, newsState } = require('../../../enum/state')


module.exports = async (req, res) => {
  const { id } = req.query
  const goodsList = await Goods.find({user: id, state: goodsState['published']}).sort({_id: -1})
  const newsList = await News.find({user: id, state: newsState['pass']}).populate('user', '_id, avatar nickname').sort({_id: -1})
  const user = await User.findOne({_id: id})
  res.json({
    data: {
      user,
      goodsList,
      newsList
    }
  })
}